# -*- py-indent-offset: 4 -*- 
# -*- tab-width: 8 -*- 
# -*- indent-tabs-mode: nil -*-
from PrettyPrinter import Print
from etgui import *
import CmdNo,string
from PageLayout import *
from ModelDictEditor import AbstrModelDictEditor,ModelDictEditor
from ModelDictEditor import SimpleModelDictEditor

class FileTypeCVEditor(ModelDictEditor):
	def NewValue(self):
		return {
			"__frame__":"File_Types_Info",
			"Name" : "NewItem"
		}
 
	def DoMakePreview(self,model):
		return MakeBorderedSectionLayout("General",
			Form(
				items=[
					"Signatures",PotTextField("Signatures"),
					"Type",PotTextField("Type"),
					"Directory",PotGuiDirSelector("Directory",gTextFieldLen)
				]
			)
		)
	def DoMakeItemEditView(self,model):
		derivedFrom=PotGuiPopupButton("Derived From")
		derivedFrom.AddItem("File Type","")   # XXX add dynamically
 
		return MakePageLayout(eVObjHExpand|eVObjVExpand,
			MakeBorderedSectionLayout("SNiFF+ Build System",
				Form(
					items=[
						"General Makefile",PotGuiFileSelector("General Makefile",gTextFieldLen,"File"),  
						"Generated From",MakeFieldLayout(derivedFrom)
					]
				)
			),
			MakeBorderedSectionLayout("Project Management and File Sharing",
				PotGuiToggleButton("Add/Remove Automatically","Add/Remove automatically to/from Project"),
				PotGuiToggleButton("Create Symbolic Link","Share with symbolic Links between WE\'s")
			),
			MakeBorderedSectionLayout("Advanced Settings",
				Form(
					items=[
						"SNiFF+ Source Code Parser",PotGuiFileSelector("Parser",gTextFieldLen,"Parser"),  
						"Icon for Project File View",PotGuiFileSelector("Icon",gTextFieldLen,"Icon"),
						"Retriever Priority",PotTextField("Retriever Priority")
					]
				),
				PotGuiToggleButton("Is Default File Type","Is Default File Type")
			)
		)

def MakeModelDictEditor(editor):
	return MakeSectionLayout(
		MakeModelDictEditorLayout(editor)
	)

def MakeDialog(model):
	panel=MakeTabSheetLayout(
#	TabPage(
#	    "AbstrModelEditor",
#	    MakeModelDictEditor(AbstrModelDictEditor(model,"FILE_TYPES"))
#	),
#	TabPage(
#	    "SimpleEditor",
#	    MakeModelDictEditor(ModelDictEditor(model,"FILE_TYPES","DICT"))
#	),
#	TabPage(
#	    "MyModelEditor",
#	    MakeModelDictEditor(TestModelDictEditor(model,"FILE_TYPES","DICT"))
#	),
		TabPage(
			"FileTypes",
			MakeModelDictEditor(FileTypeCVEditor(model,"FILE_TYPES","FileType"))
		),
	)
	modelio=ModelIO(model)
	dialog=PotGuiDialog(
		model,
		MakeDialogWithButtons(
			panel,
			ActionButton(CmdNo.cIdOk,"OK",default=1),
			ActionButton(CmdNo.cIdCancel,"Cancel"),
			ActionButton("Load",action=modelio.Load),
			ActionButton("Save",action=modelio.Save)
 
		),
		"Pot GUI",
		eWinDefault
	)
	return dialog
gDialog=None
def Show():
	global gDialog
	if not gDialog:
		model=PotGuiModel()
		model.SetValue("FILE_TYPES",EnvGetDict("FILE_TYPES"))
		gDialog=MakeDialog(model)
	gDialog.ShowUnderMouse()
